package com.yoso.newx;

import com.yoso.domain.SecInfo;
import com.yoso.domain.User;
import org.junit.jupiter.api.Test;

import java.util.Optional;

/**
 * @author shizejin
 * @date 2022/2/17
 * @description:
 */
public class Option {
    /**
    *
    */
    @Test
    public void test(){
        User user = new User();
        user.setId("2367");
        Optional<User> userOptional = Optional.ofNullable(user);
        String s = userOptional.map(User::getSecInfo)
                .map(SecInfo::getSecCode)
                .orElseThrow(()->new NullPointerException(""));
        System.out.println("s = " + s);
        System.out.println("user.getSecInfo().getSecCode() = " + user.getSecInfo().getSecCode());
    }
}
